heap operations
Advanced |
| Works with vectors |
| A heap is a binary tree in which every node is |
| larger than the values associated with either |
| child. A heap and a binary tree, for that matter, |
| can be very efficiently stored in a vector, by |
| placing the children of node i in positions 2 * i +
| 1 and 2 * i + 2. |
| Using this encoding, the largest value in the |
| heap is always located in the initial position, and
| can therefore be very efficiently retrieved. |